import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'logic.dart';

class FlowListPage extends StatelessWidget {
  const FlowListPage({super.key});

  @override
  Widget build(BuildContext context) {
    final FlowListLogic logic = Get.find<FlowListLogic>();
    final state = logic.state;
    return Scaffold(
        appBar: AppBar(title: const Text("流程列表")),
        body: Obx(() {
          return ListView.builder(
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemCount: state.flows.length,
              itemBuilder: (BuildContext context, int index) {
                var bean = state.flows[index];
                return Container(
                    margin: const EdgeInsets.all(5),
                    decoration: BoxDecoration(
                        color: Colors.blue.withAlpha(30),
                        borderRadius: BorderRadius.circular(5)),
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            "Id:${bean.id}",
                            style: const TextStyle(fontWeight: FontWeight.bold),
                          ),
                          Text("流程描述：${bean.description}"),
                          Text("程序步骤：${bean.step}"),
                          Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                InkWell(
                                  onTap: () {
                                    logic.runFlow(bean.id);
                                  },
                                  child: const Padding(
                                    padding: EdgeInsets.all(8.0),
                                    child: Text(
                                      "运行",
                                      style: TextStyle(
                                          color: Colors.blue,
                                          fontWeight: FontWeight.bold),
                                    ),
                                  ),
                                ),
                                InkWell(
                                    onTap: () {
                                      logic.editFlowConfig(bean.id);
                                    },
                                    child: const Padding(
                                        padding: EdgeInsets.all(8.0),
                                        child: Text("编辑",
                                            style: TextStyle(
                                                color: Colors.blue,
                                                fontWeight: FontWeight.bold)))),
                                InkWell(
                                    onTap: () {
                                      logic.deleteFlow(bean.id);
                                    },
                                    child: const Padding(
                                        padding: EdgeInsets.all(8.0),
                                        child: Text("删除",
                                            style: TextStyle(
                                                color: Colors.red,
                                                fontWeight: FontWeight.bold))))
                              ])
                        ]));
              });
        }),
        floatingActionButton: FloatingActionButton(
            onPressed: logic.addFlow,
            shape: const CircleBorder(),
            child: const Icon(Icons.add)));
  }
}
